package com.jye.rseven.user.serivce.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.jye.rseven.domain.Task;
import com.jye.rseven.domain.TyPtCode;
import com.jye.rseven.domain.User;
import com.jye.rseven.service.TyPtCodeService;
import com.jye.rseven.user.mapper.TyPtCodeMapper;
import com.jye.rseven.user.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Service
public class TyPtCodeServiceImpl implements TyPtCodeService {

    @Autowired
    TyPtCodeMapper tyPtCodeMapper;

    @Autowired
    UserMapper userMapper;

    @Override
    public int addTy(TyPtCode tyPtCode) {
        try{
            tyPtCodeMapper.addTy(tyPtCode);
            return 1;
        }catch (Exception e){
            return 0;
        }
    }

    @Override
    public int updatePtStatus(int type2, String pid) {
       try{
            tyPtCodeMapper.updatePtStatus(type2,pid);
            return 1;
        }catch (Exception e){
            return 0;
        }
    }

    @Override
    public List<TyPtCode> findPtByUId(int uId, int skip, int limit) {
        User u = userMapper.findUserById(uId);
        List<TyPtCode> list = tyPtCodeMapper.findPtByUId(uId,skip,limit);
        for (TyPtCode ty: list){
            ty.setUser(u);
        }

        return list;
    }

    @Override
    public TyPtCode findPtById(int id) {
        User u = userMapper.findUserById(tyPtCodeMapper.findUidById(id));
        TyPtCode ty = tyPtCodeMapper.findPtById(id);
        ty.setUser(u);
        return ty;

    }

    @Override
    public int findUidById(int id) {
        return tyPtCodeMapper.findUidById(id);
    }

}
